<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<script type="text/javascript" charset="UTF-8" src="/ecadmin/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/ecadmin/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/ecadmin/css/smoothness.datepick.css" />
<script>
$(function(){
	$('#search').click(function(){
		document.searchForm.submit();
	});
	$('#toUpdateMsg').click(function(){
		location.href='/ecadmin/memberMsg/toUpdate.do';
	});
	$('#createTemplate').click(function(){
		location.href='/ecadmin/memberMsg/toUpdateTemplate.do';
	});
	$('#templateList').click(function(){
		location.href='/ecadmin/memberMsg/templateList.do';
	});
	$('#startSendDate').datepick({dateFormat:'yy-mm-dd'});
	$('#endSendDate').datepick({dateFormat:'yy-mm-dd'});
	
});
function deleteMsg(msgId){
	if(confirm('确定删除？')){
	location.href='/ecadmin/memberMsg/deleteMsg.do?msgId='+msgId;
	}
	return false;
}
</script>
${pu:reqSet('tempHql', 'from MemberMsgTemplate order by id asc') }
${pu:reqSet('templates', pu:queryByHql(tempHql, null, null)) }
<c-rt:set var="theHour" scope="request">
<fmt-rt:formatDate value="${pu:currentDate()}" pattern="HH"/>
</c-rt:set>
<c-rt:set var="theHour" scope="request">
${pu:toLong(theHour)+1 }
</c-rt:set>
<c-rt:if test="${pu:toLong(theHour)==24}">
${pu:reqSet('theHour', '00:00' }
</c-rt:if>
<c-rt:if test="${pu:toLong(theHour)!=24}">

<c-rt:if test="${pu:toLong(theHour)<10}">
<c-rt:set var="theHour" scope="request">
0${theHour }
</c-rt:set>
</c-rt:if>
<c-rt:set var="theHour" scope="request">
${theHour }:00
</c-rt:set>
</c-rt:if>

<c-rt:if test="${!empty param.endSendTime}">
${pu:reqSet('theHour', param.endSendTime) }
</c-rt:if>

<c-rt:set var="tp" value="${pu:pageableTag('tpp', 20, 10)}" scope="request"/>
${pu:criteriaForName('com.yaodian100.ec.membermsg.entity.MemberMsg') }
<c-rt:set var="sendDateS" scope="request">${param.startSendDate} ${param.startSendTime}</c-rt:set>
<c-rt:set var="sendDateE" scope="request">${param.endSendDate} ${param.endSendTime}</c-rt:set>
${pu:criteriaAdd(pu:criteria('ge', 'sendTime', pu:toDate(sendDateS, 'yyyy-MM-dd HH:mm'))) }
${pu:criteriaAdd(pu:criteria('le', 'sendTime', pu:toDate(sendDateE, 'yyyy-MM-dd HH:mm'))) }
<c-rt:if test="${!empty param.tempId}">
${pu:criteriaAdd(pu:criteria('eq', 'tempId', pu:toLong(param.tempId))) }
</c-rt:if>
<c-rt:if test="${!empty param.type}">
${pu:criteriaAdd(pu:criteria('eq', 'sendType', param.type)) }
</c-rt:if>
<c-rt:if test="${!empty param.status}">
${pu:criteriaAdd(pu:criteria('eq', 'status', param.status)) }
</c-rt:if>
${pu:criteriaAddOrder(pu:criteriaOrderDesc('createDate')) }
${pu:reqSet('results', pu:criteriaResult(tp)) }

	
${pu:reqSet('startSendDate', param.startSendDate) }
${pu:reqSet('endSendDate', param.endSendDate) }
<c-rt:if test="${empty startSendDate}">
<c-rt:set var="startSendDate" scope="request">
<fmt-rt:formatDate value="${pu:addDays(pu:currentDate(), -30)}" pattern="yyyy-MM-dd"/>
</c-rt:set>
</c-rt:if>
<c-rt:if test="${empty endSendDate}">
<c-rt:set var="endSendDate" scope="request">
<fmt-rt:formatDate value="${pu:currentDate()}" pattern="yyyy-MM-dd"/>
</c-rt:set>
</c-rt:if>
<br />
<h1>会员通知管理

</h1>
${errMsg }
<form name="searchForm" id="searchForm">
<table width="100%">
<tr>
<td>发送时间:
<input type="text" value="${startSendDate }" name="startSendDate" id="startSendDate" size="10"/>
<select name="startSendTime">
<c-rt:forEach begin="0" end="23" varStatus="sIndex">
<c-rt:set var="sHour" scope="request">${sIndex.index }:00</c-rt:set>
<c-rt:if test="${sIndex.index<10}">
<c-rt:set var="sHour" scope="request">0${sIndex.index }:00</c-rt:set>
</c-rt:if>
<option value="${sHour }" <c-rt:if test="${param.startSendTime==sHour }">selected="selected"</c-rt:if>>${sHour }</option>
</c-rt:forEach>
</select>
~
<input type="text" value="${endSendDate }" name="endSendDate" id="endSendDate" size="10"/>
<select name="endSendTime">
<c-rt:forEach begin="0" end="23" varStatus="eIndex">
<c-rt:set var="eHour" scope="request">${eIndex.index }:00</c-rt:set>
<c-rt:if test="${eIndex.index<10}">
<c-rt:set var="eHour" scope="request">0${eIndex.index }:00</c-rt:set>
</c-rt:if>

<option value="${eHour }" <c-rt:if test="${theHour==eHour }">selected="selected"</c-rt:if>>${eHour }</option>
</c-rt:forEach>
</select>
</td>
<td></td>
</tr>
<tr>
<td>
范  本：<select name="tempId">
<option value="">全部</option>
<c-rt:forEach items="${templates}" var="temp">
<option value="${temp.id }" <c-rt:if test="${param.tempId==temp.id }">selected="selected"</c-rt:if>>${temp.title }</option>
</c-rt:forEach>
</select>
发送工具：<select name="type">
<option value="">全部</option>
<option value="1" <c-rt:if test="${param.type=='1' }">selected="selected"</c-rt:if>>系统信</option>
<option value="2" <c-rt:if test="${param.type=='2' }">selected="selected"</c-rt:if>>短信</option>
</select>
发送状态：
<select name="status">
<option value="">全部</option>
<option value="0" <c-rt:if test="${param.status=='0' }">selected="selected"</c-rt:if>>待发送</option>
<option value="1" <c-rt:if test="${param.status=='1' }">selected="selected"</c-rt:if>>发送中</option>
<option value="2" <c-rt:if test="${param.status=='2' }">selected="selected"</c-rt:if>>已完成</option>
<option value="3" <c-rt:if test="${param.status=='3' }">selected="selected"</c-rt:if>>已删除</option>
<option value="3" <c-rt:if test="${param.status=='4' }">selected="selected"</c-rt:if>>失败</option>
</select>
</td>
<td><div class="f-link"><a href="javascript:;" id="search">搜寻</a></div></td>
</tr>
<tr>
<td></td>
<td>
<div class="f-link"><a href="javascript:;" id="templateList">范本列表</a></div>
<div class="f-link"><a href="#" id="toUpdateMsg">新增会员通知</a></div></td>
</tr>
</table>
</form>

<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th>序号</th>
				<th>范本</th>
				<th>发送工具</th>
				<th>建立时间</th>
				<th>发送时间</th>
				<th>状态</th>
				<th>已发</th>
				<th>未发</th>
				<th>发送人</th>
			</tr>
		</thead>
		<tbody>
			<c-rt:forEach items="${results}" var="msg" varStatus="rows_index">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">
					<td>
					${msg.id }				
					</td>
					<td>
					${pu:reqSet('thisTemp', pu:get('com.yaodian100.ec.membermsg.entity.MemberMsgTemplate', msg.tempId)) }
					<a href="/ecadmin/memberMsg/viewDetail.do?msgId=${msg.id }">${thisTemp.title }</a>
					</td>
					<td>
					<c-rt:if test="${msg.sendType=='1'}">系统信</c-rt:if><c-rt:if test="${msg.sendType=='2'}">短信</c-rt:if>
					</td>
					<td><fmt-rt:formatDate value="${msg.createDate}" pattern="yyyy/MM/dd HH:mm"/></td>
					<td><fmt-rt:formatDate value="${msg.sendTime}" pattern="yyyy/MM/dd HH:mm"/></td>
					<td>
					<c-rt:if test="${msg.status=='0'}">
					待发送（<a href="javascript:void(0);" onclick="deleteMsg('${msg.id }')">删除</a>）
					</c-rt:if>
					<c-rt:if test="${msg.status=='1'}">
					发送中
					</c-rt:if>
					<c-rt:if test="${msg.status=='2'}">
					已完成
					</c-rt:if>
					<c-rt:if test="${msg.status=='3'}">
					已删除
					</c-rt:if>
					<c-rt:if test="${msg.status=='4'}">
					失败
					</c-rt:if>
					</td>
					<td> 
					${pu:reqSet('successCount', 0) }
					${pu:reqSet('unsuccessCount', 0) }
					${pu:reqSet('success', '') }
					${pu:reqSet('unsuccess', '') }
					<c-rt:if test="${!empty msg.success && msg.success!='null'}">
					${pu:reqSet('successCount', pu:arrayLength(pu:split(msg.success, ','))) }
					${pu:reqSet('success', msg.success) }
					</c-rt:if>
					<c-rt:if test="${!empty msg.unsuccess && msg.unsuccess!='null'}">
					${pu:reqSet('unsuccessCount', pu:arrayLength(pu:split(msg.unsuccess, ','))) }
					${pu:reqSet('unsuccess', msg.unsuccess) }
					</c-rt:if>
					
					<c-rt:choose>
					<c-rt:when test="${empty msg.success || msg.status!='2'}">
					-
					</c-rt:when>
					<c-rt:when test="${!empty msg.success && msg.status=='2'}">
					<a href="javascript:document.successOrder${rows_index.index }.submit()">${successCount }笔</a>
					<form id="successOrder${rows_index.index }" name="successOrder${rows_index.index }" method="post" action="/ecadmin/jsp/downloadOrderList.jsp">
					<input type="hidden" name="file" value="successOrderList.txt"/>
					<input type="hidden" name="content" value="${msg.success }"/>
					</form>
					</c-rt:when>
					</c-rt:choose>
					</td>
					<td>
					<c-rt:choose>
					<c-rt:when test="${empty msg.unsuccess || msg.status=='1' || msg.status=='4'}">
					-
					</c-rt:when>
					<c-rt:when test="${(!empty msg.unsuccess && msg.status=='0') || msg.status=='3'}">
					
					${pu:reqSet('content', unsuccess) }
					<c-rt:if test="${!empty unsuccess && !empty success}">
					<c-rt:set var="unsuccessCount" scope="request" value="${successCount+unsuccessCount}"/>
					
					<c-rt:set var="content" scope="request">
					${content },${success }
					</c-rt:set>
					</c-rt:if>
					<c-rt:if test="${empty content && !empty success}">
					<c-rt:set var="content" scope="request">
					${success }
					</c-rt:set>
					</c-rt:if>
					
					<a href="javascript:document.unsuccessOrder${rows_index.index }.submit()">${unsuccessCount }笔</a>
					<form id="unsuccessOrder${rows_index.index }" name="unsuccessOrder${rows_index.index }" method="post" action="/ecadmin/jsp/downloadOrderList.jsp">
					<input type="hidden" name="file" value="unsuccessOrderList.txt"/>
					<input type="hidden" name="content" value="${content }"/>
					</form>
					</c-rt:when>
					<c-rt:when test="${!empty unsuccess && msg.status=='2'}">
					${pu:reqSet('content', unsuccess) }
					
					<a href="javascript:document.unsuccessOrder${rows_index.index }.submit()">${unsuccessCount }笔</a>
					<form id="unsuccessOrder${rows_index.index }" name="unsuccessOrder${rows_index.index }" method="post" action="/ecadmin/jsp/downloadOrderList.jsp">
					<input type="hidden" name="file" value="unsuccessOrderList.txt"/>
					<input type="hidden" name="content" value="${content }"/>
					</form>
					</c-rt:when>
					</c-rt:choose>
					</td>
					<td>${pu:reqSet('createUser', pu:get('com.yaodian100.core.admin.entity.User', msg.createUser)) }
					${createUser.group.description }-${msg.createUser }
					</td>
				</tr>
			</c-rt:forEach>
		</tbody>
	</table>
<c-rt:set var="url">
/ecadmin/memberMsg/list.do
</c-rt:set>
<pageable:Pageable url="${url}" formname="newForm" key="tpp"></pageable:Pageable>
<script>

$(document).ready(function(){
	$('#questionToAdd').click(function(){
		doAR('<%=application.getContextPath() %>/cs/page.do?iamlazy=selectType&AJAX=true&refreshZone=main', 'main');
	});
	$('#cs').click(function(){
		doAR('<%=application.getContextPath() %>/cs/page.do?iamlazy=list&AJAX=true&refreshZone=main', 'main', 'workOrderForm');
	});
	$('#workOrderForm').submit(function(){
		doAR('<%=application.getContextPath() %>/cs/page.do?iamlazy=list&AJAX=true&refreshZone=main', 'main', 'workOrderForm');
	});
});
</script>